// task_select_options_model.dart
import 'package:json_annotation/json_annotation.dart';

part 'task_select_options_model.g.dart';

@JsonSerializable()
class TaskSelectOptionsModel {
  @JsonKey(name: 'approveDurationOptions')
  final List<TaskSelectOptionsItemModel>? approveDurationOptions;

  @JsonKey(name: 'bidTimesPerUserOptions')
  final List<TaskSelectOptionsItemModel>? bidTimesPerUserOptions;

  @JsonKey(name: 'deviceTypes')
  final List<TaskSelectOptionsItemModel>? deviceTypes;

  @JsonKey(name: 'submitDurationOptions')
  final List<TaskSelectOptionsItemModel>? submitDurationOptions;

  @JsonKey(name: 'taskDescrption')
  final String? taskDescription;

  @JsonKey(name: 'taskDurationOptions')
  final List<TaskSelectOptionsItemModel>? taskDurationOptions;

  TaskSelectOptionsModel({
    this.approveDurationOptions,
    this.bidTimesPerUserOptions,
    this.deviceTypes,
    this.submitDurationOptions,
    this.taskDescription,
    this.taskDurationOptions,
  });

  factory TaskSelectOptionsModel.fromJson(Map<String, dynamic> json) =>
      _$TaskSelectOptionsModelFromJson(json);

  Map<String, dynamic> toJson() => _$TaskSelectOptionsModelToJson(this);
}

@JsonSerializable()
class TaskSelectOptionsItemModel {
  final String optionDisplay;
  final String optionValue;

  TaskSelectOptionsItemModel({
    required this.optionDisplay,
    required this.optionValue,
  });

  factory TaskSelectOptionsItemModel.fromJson(Map<String, dynamic> json) {
    // 手动处理optionValue，确保它是String类型
    final value = json['optionValue'];
    final String optionValueStr = value is int ? value.toString() : value as String;

    return TaskSelectOptionsItemModel(
      optionDisplay: json['optionDisplay'] as String,
      optionValue: optionValueStr,
    );
  }

  Map<String, dynamic> toJson() => _$TaskSelectOptionsItemModelToJson(this);
}
